﻿using System;
using System.Collections.Generic;
using ArmyBuilder_Modele;
using ArmeeBuilder_Metier;

namespace ArmyBuilder_Controller
{
    public class FicheInfo
    {   
        private IRaceModele m_oRaceSelected;
        public  IRaceModele oRaceSelected
        {
            get{ return m_oRaceSelected; }
            set
            {
                m_oRaceSelected = value;

                if( m_oRaceSelected != null )
                {
                    m_listUniteAffichable = null;
                }
            }
        }

        private ICategorieModele m_oCategorieSelected;
        public ICategorieModele oCategorieSelected 
        {
            get{ return m_oCategorieSelected; }
            set
            {
                m_oCategorieSelected = value;

                if( m_oCategorieSelected != null )
                {
                    m_listUniteAffichable = null;
                }
            }
        }

        private List<IUniteModele> m_listUniteAffichable;
        public List<IUniteModele> ListUniteAffichable()
        {            
            if(m_listUniteAffichable == null && oRaceSelected != null && oCategorieSelected != null)
            {
                m_listUniteAffichable = Unite.GetListUnite(oRaceSelected.Code, oCategorieSelected.Code);
                return m_listUniteAffichable;
            }
            return new List<IUniteModele>();
        }

        public IUniteModele oUniteSelected;        

        public FicheInfo()
        {            
        }

        public static List<IRaceModele> ListRaceDisplayable()
        {
            return Race.List();
        }
        
        public static List<ICategorieModele> ListCategorieDisplayable()
        {
            return Categorie.List();            
        }

        public void OnChangeRace( string strCodeRace )
        {
            oRaceSelected = Race.Find(strCodeRace);
        }

        public void OnChangeCategorie( string strCodeCategorie )
        {
            oCategorieSelected = Categorie.Find(strCodeCategorie);
        }
        
        public void OnChangeUnite( string strCodeUnite )
        {
            oUniteSelected = Unite.Find(strCodeUnite);
        }   
     
        public void OnImportArmee()
        {
            Armee.ImportArmee();
        }  
    }
}
